#pragma once


#define		PROJECT_TREE_ROOT_NODE			0
#define		PROJECT_TREE_CASE_ROOT_NODE		1
#define		PROJECT_TREE_CASE_NODE			2
#define		PROJECT_TREE_SOURCE_ROOT_NODE	3
#define		PROJECT_TREE_SOURCE_NODE		4
#define		PROJECT_TREE_DATASET_NODE		5
#define		PROJECT_TREE_BAND_NODE			6

// zxCheckProjectTreeCtrl

class AFX_EXT_CLASS zxCheckProjectTreeCtrl : public CTreeCtrl
{
	DECLARE_DYNAMIC(zxCheckProjectTreeCtrl)

public:
	zxCheckProjectTreeCtrl();
	virtual ~zxCheckProjectTreeCtrl();

protected:
	CImageList m_il;

	HTREEITEM	m_hSource;
	HTREEITEM	m_hCase;

	HTREEITEM	m_hSelected;

	ck::CheckProject* m_pProject;

public:
	void		AttachBitmap();
	void		Clear();

public:
	void		Populate(ck::CheckProject* pProject);

	RESULTCODE	AddDataProduct(ck::product::DataProduct* pProduct);

	RESULTCODE	AddDataSource(ck::DataSource* pDataSource);

protected:
	void		SetProjectName();
	void		PopulateCheckCase();
	void		PopulateDataSource();

	void		PopulateDataSourceNode(HTREEITEM hSourceItem, ck::DataSource* pDataSource);
	void		PopulateDataSourceNode(HTREEITEM hSourceItem, ck::FileDataSource* pDataSource);
	void		PopulateDataSourceNode(HTREEITEM hSourceItem, ck::FolderDataSource* pDataSource);

	void		PopulateDatasetNode(HTREEITEM hDatasetItem, ck::data::Dataset* pDataset);
	void		PopulateRaterBandNode(HTREEITEM hDatasetItem, ck::data::RasterDataset* pRasterDataset);

protected:
	void		Cleanup();
	void		CleanupCases();
	void		CleanupDataSources();
	void		RemoveDataSourceNode(HTREEITEM hDataSourceItem);
	void		CleanupDataSourceNode(HTREEITEM hDataSourceItem);

	void		RemoveDatasetNode(HTREEITEM hDataSetItem, ck::data::Dataset* pDataset);
	void		CleanupDatasetNode(HTREEITEM hDataSetItem);
	void		CleanupDatasetNode(HTREEITEM hDataSetItem, ck::data::Dataset* pDataset);
	void		CleanupRasterBandNode(HTREEITEM hRaster);

protected:
	int			GetNodeType(HTREEITEM hItem);
	int			GetDataSourceNodeIcon(ck::DataSource* pDataSource);

protected:
	DECLARE_MESSAGE_MAP()
public:
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnNMDblclk(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnNMRClick(NMHDR *pNMHDR, LRESULT *pResult);
};


